<?php
if ( !function_exists( 'yag_view_admin_settings' ) ) {
	function yag_view_admin_settings() {
		
		$yag_settings = get_option('yag_options'); 
		$pages = get_pages();
		$count = count( $pages );
?>
<style>
	ul.yag { list-style-type: none; margin: auto; height: 20px; }
	.yag li { float: left; padding-left: 5px; padding-right: 5px; width:20%}
	#yag_example_container { 
		color: <?php echo $yag_settings['pretty_pretty_colors']['style_color']?>; 
		background-color: <?php echo $yag_settings['pretty_pretty_colors']['style_background']?>; 
		border: 1px solid <?php echo $yag_settings['pretty_pretty_colors']['style_border_color']?>;
		padding:5px; 
		width: 250px;
	}
</style>
<div class="yag-settings">
	<div id="icon-options-general" class="icon32"></div>
	<h2>Glossary Options (aka Yagtions)</h2>
	<br />
	<div style="clear:both;"></div>
	<div class="widefat">
		<form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" style="padding: 5px">
			<p>
				<input class='button-primary' type='submit' name='Save' value='<?php _e('Save Options'); ?>' id='submitbutton' />
			</p>
			<h3>Which Pages</h3>
			<ul class="yag">
				<li style="border-bottom: 1px solid #bdbdbd">
					<input 
						type="checkbox" 
						name="yag_on_page[]" 
						value="all" 
						id="yag_on_all_page"
						<?php echo ( in_array( 'all', $yag_settings['yag_on_page'] ) ) ? 'checked="checked"': NULL ?>
					/>
					<label for="yag_on_all_page">All Pages</label>
				</li>
			</ul>
			<div style="clear:both;"></div>
			<ul class="yag">
			<?php foreach ( $pages as $page ): ?>
				<li>
					<input 
						type="checkbox" 
						name="yag_on_page[]" 
						value="<?php echo $page->post_name ?>" 
						class="yag_on_page"
						<?php if ( in_array($page->post_name, $yag_settings['yag_on_page'] ) ): ?>
						checked = "checked"
						<?php endif; ?>
						id="yag_on_page_<?php echo $page->post_name ?>" />
					<label 
						for="yag_on_page_<?php echo $page->post_name?>">
							<?php echo $page->post_title ?>
						</label>
				</li>
			<?php endforeach; ?>						
			</ul>
			<div style="clear:both;"></div>
			<h3>Styling</h3>
			<div style="width:40%; float: left">
				<p>
					<label for="style_background">Background Color: </label>
					<input 
						class="yag_style_picker_input" 
						id="style_background" 
						type="text" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_background']?>" 
						name="style_background"
						rel="colorpicker_backgound"
					/>
					<input 
						id="style_background_prev" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_background']?>" 
						type="hidden" />
					<div 
						class="yag_style_picker" 
						id="colorpicker_backgound" 
						rel="style_background">
					</div>
				</p>
				<div style="clear:both;"></div>
				<p>
					<label for="style_color">Text Color: </label>
					<input 
						class="yag_style_picker_input" 
						id="style_color" 
						type="text" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_color']?>" 
						name="style_color" 
						rel="colorpicker_color"
						/>
					<input 
						id="style_background_prev" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_color']?>" 
						type="hidden" />
					<div 
						class="yag_style_picker" 
						id="colorpicker_color" 
						rel="style_color">
					</div>
				</p>
			<div style="clear:both;"></div>
				<p>
					<label for="style_border_color">Border Color: </label>
					<input 
						class="yag_style_picker_input" 
						id="style_border_color" 
						type="text" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_border_color']?>" 
						name="style_border_color" 
						rel="colorpicker_border_color"
						/>
					<input 
						id="style_background_prev" 
						value="<?php echo $yag_settings['pretty_pretty_colors']['style_border_color']?>" 
						type="hidden"
						/>
					<div 
						class="yag_style_picker" 
						id="colorpicker_border_color" 
						rel="style_border_color">
					</div>
				</p>
			</div>
				<div style="width:55%;float:right;padding-top:2%;">
					<div id="yag_example_container">
						Ipsome gipsom gloria idaho et all. 
						Tu eta blurbeus uno gracias.  
						Wait, what?
					</div>
				</div>
			<div style="clear:both;"></div>
			<p>
				<input class='button-primary' type='submit' name='Save' value='<?php _e('Save Options'); ?>' id='submitbutton' />
			</p>
			<?php 
				wp_nonce_field( 'admin_settings.php', 'yag_settings_page' ); 
			?>
		
		</form>
	</div>
</div>
<script type="text/javascript">
   jQuery(document).ready(function() {
     jQuery('.yag_style_picker').hide();

     jQuery('.yag_style_picker_input').focus(function(){
			jQuery('.yag_style_picker').hide();
			jQuery('#' + jQuery(this).attr('rel')).fadeIn();
     });

     jQuery('#colorpicker_backgound').farbtastic(function(color){
     		jQuery('#style_background').css('background-color',color).val(color);
     		jQuery('#yag_example_container').css('background-color',color);
   		});
		
     jQuery('#colorpicker_color').farbtastic(function(color){
     		jQuery('#style_color').css('background-color',color).val(color);
     		jQuery('#yag_example_container').css('color',color);
	   	});
	   	
     jQuery('#colorpicker_border_color').farbtastic(function(color){
     		jQuery('#style_border_color').css('background-color',color).val(color);
     		jQuery('#yag_example_container').css('border-color',color);
	   	});

	 jQuery('#yag_on_all_page').click(function(){ 
		 	if( jQuery(this).attr('checked') == 'checked') { jQuery('input.yag_on_page').attr('checked', true); }
			else { jQuery('input.yag_on_page').attr('checked', false);}
		});
     });
 </script>
 
<?php		

	}
}
?>